<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Json_Server - JSON-RPC server - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.json.server.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.json.server.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.json.xml2json.html">XML to JSON conversion</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.json.html">Zend_Json</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.layout.html">Zend_Layout</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.json.server" class="section"><div class="info"><h1 class="title">Zend_Json_Server - JSON-RPC server</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Json_Server</span> is a <a href="http://groups.google.com/group/json-rpc/" class="link external">&raquo; JSON-RPC</a> server implementation.
        It supports both the <a href="http://json-rpc.org/wiki/specification" class="link external">&raquo; JSON-RPC
            version 1 specification</a> as well as the <a href="http://groups.google.com/group/json-rpc/web/json-rpc-1-2-proposal" class="link external">&raquo; version 2
            specification</a>; additionally, it provides a <acronym class="acronym">PHP</acronym> implementation
        of the <a href="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal" class="link external">&raquo; Service
            Mapping Description (SMD) specification</a>
        for providing service metadata to service consumers.
    </p>

    <p class="para">
        JSON-RPC is a lightweight Remote Procedure Call protocol that utilizes
        <acronym class="acronym">JSON</acronym> for its messaging envelopes. This JSON-RPC implementation follows
        <acronym class="acronym">PHP</acronym>&#039;s <a href="http://www.php.net/manual/en/class.soapserver.php" class="link external">&raquo; SoapServer</a>
        <acronym class="acronym">API</acronym>. This means, in a typical situation, you will simply:
    </p>

    <ul class="itemizedlist">
        <li class="listitem"><p class="para">Instantiate the server object</p></li>

        <li class="listitem">
            <p class="para">Attach one or more functions and/or classes/objects to the server object</p>
        </li>

        <li class="listitem"><p class="para">handle() the request</p></li>
    </ul>

    <p class="para">
        <span class="classname">Zend_Json_Server</span> utilizes <a href="zend.server.reflection.html" class="link">Zend_Server_Reflection</a>
        to perform reflection on any attached classes or functions, and uses that
        information to build both the SMD and enforce method call signatures. As
        such, it is imperative that any attached functions and/or class methods
        have full <acronym class="acronym">PHP</acronym> docblocks documenting, minimally:
    </p>

    <ul class="itemizedlist">
        <li class="listitem"><p class="para">All parameters and their expected variable types</p></li>
        <li class="listitem"><p class="para">The return value variable type</p></li>
    </ul>

    <p class="para">
        <span class="classname">Zend_Json_Server</span> listens for POST requests only at this
        time; fortunately, most JSON-RPC client implementations in the wild at
        the time of this writing will only POST requests as it is. This makes it
        simple to utilize the same server end point to both handle requests as
        well as to deliver the service SMD, as is shown in the next example.
    </p>

    <div class="example" id="zend.json.server.usage"><div class="info"><p><b>Example #1 Zend_Json_Server Usage</b></p></div>
        

        <div class="example-contents"><p>
            First, let&#039;s define a class we wish to expose via the JSON-RPC
            server. We&#039;ll call the class &#039;Calculator&#039;, and define methods for
            &#039;add&#039;, &#039;subtract&#039;, &#039;multiply&#039;, and &#039;divide&#039;:
        </p></div>

        <pre class="programlisting brush: php">
/**
 * Calculator - sample class to expose via JSON-RPC
 */
class Calculator
{
    /**
     * Return sum of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return int
     */
    public function add($x, $y)
    {
        return $x + $y;
    }

    /**
     * Return difference of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return int
     */
    public function subtract($x, $y)
    {
        return $x - $y;
    }

    /**
     * Return product of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return int
     */
    public function multiply($x, $y)
    {
        return $x * $y;
    }

    /**
     * Return the division of two variables
     *
     * @param  int $x
     * @param  int $y
     * @return float
     */
    public function divide($x, $y)
    {
        return $x / $y;
    }
}
</pre>


        <div class="example-contents"><p>
            Note that each method has a docblock with entries indicating each
            parameter and its type, as well as an entry for the return value.
            This is <em class="emphasis">absolutely critical</em> when utilizing
            <span class="classname">Zend_Json_Server</span> or any other server component in
            Zend Framework, for that matter.
        </p></div>

        <div class="example-contents"><p>
            Now we&#039;ll create a script to handle the requests:
        </p></div>

        <pre class="programlisting brush: php">
$server = new Zend_Json_Server();

// Indicate what functionality is available:
$server-&gt;setClass(&#039;Calculator&#039;);

// Handle the request:
$server-&gt;handle();
</pre>


        <div class="example-contents"><p>
            However, this will not address the issue of returning an SMD so that
            the JSON-RPC client can autodiscover methods. That can be
            accomplished by determining the <acronym class="acronym">HTTP</acronym> request method, and then
            specifying some server metadata:
        </p></div>

        <pre class="programlisting brush: php">
$server = new Zend_Json_Server();
$server-&gt;setClass(&#039;Calculator&#039;);

if (&#039;GET&#039; == $_SERVER[&#039;REQUEST_METHOD&#039;]) {
    // Indicate the URL endpoint, and the JSON-RPC version used:
    $server-&gt;setTarget(&#039;/json-rpc.php&#039;)
           -&gt;setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);

    // Grab the SMD
    $smd = $server-&gt;getServiceMap();

    // Return the SMD to the client
    header(&#039;Content-Type: application/json&#039;);
    echo $smd;
    return;
}

$server-&gt;handle();
</pre>


        <div class="example-contents"><p>
            If utilizing the JSON-RPC server with Dojo toolkit, you will also
            need to set a special compatibility flag to ensure that the two
            interoperate properly:
        </p></div>

        <pre class="programlisting brush: php">
$server = new Zend_Json_Server();
$server-&gt;setClass(&#039;Calculator&#039;);

if (&#039;GET&#039; == $_SERVER[&#039;REQUEST_METHOD&#039;]) {
    $server-&gt;setTarget(&#039;/json-rpc.php&#039;)
           -&gt;setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
    $smd = $server-&gt;getServiceMap();

    // Set Dojo compatibility:
    $smd-&gt;setDojoCompatible(true);

    header(&#039;Content-Type: application/json&#039;);
    echo $smd;
    return;
}

$server-&gt;handle();
</pre>

    </div>

    <div class="section" id="zend.json.server.details"><div class="info"><h1 class="title">Advanced Details</h1></div>
        

        <p class="para">
            While most functionality for <span class="classname">Zend_Json_Server</span> is
            spelled out in <a href="zend.json.server.html#zend.json.server.usage" class="link">this section</a>, more
            advanced functionality is available.
        </p>

        <div class="section" id="zend.json.server.details.zendjsonserver"><div class="info"><h1 class="title">Zend_Json_Server</h1></div>
            

            <p class="para">
                <span class="classname">Zend_Json_Server</span> is the core class in the JSON-RPC
                offering; it handles all requests and returns the response
                payload. It has the following methods:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addFunction($function)</span>: Specify a
                        userland function to attach to the server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setClass($class)</span>: Specify a class
                        or object to attach to the server; all public methods of
                        that item will be exposed as JSON-RPC methods.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">fault($fault = null, $code = 404, $data = null)</span>:
                        Create and return a <span class="classname">Zend_Json_Server_Error</span> object.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">handle($request = false)</span>: Handle a
                        JSON-RPC request; optionally, pass a
                        <span class="classname">Zend_Json_Server_Request</span> object to utilize
                        (creates one by default).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getFunctions()</span>: Return a list of
                        all attached methods.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setRequest(Zend_Json_Server_Request $request)</span>:
                        Specify a request object for the server to utilize.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getRequest()</span>: Retrieve the request
                        object used by the server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setResponse(Zend_Json_Server_Response $response)</span>:
                        Set the response object for the server to utilize.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getResponse()</span>: Retrieve the
                        response object used by the server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setAutoEmitResponse($flag)</span>:
                        Indicate whether the server should automatically emit
                        the response and all headers; by default, this is
                        <b><tt>TRUE</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">autoEmitResponse()</span>: Determine if
                        auto-emission of the response is enabled.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getServiceMap()</span>: Retrieve the
                        service map description in the form of a
                        <span class="classname">Zend_Json_Server_Smd</span> object
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.json.server.details.zendjsonserverrequest"><div class="info"><h1 class="title">Zend_Json_Server_Request</h1></div>
            

            <p class="para">
                The JSON-RPC request environment is encapsulated in the
                <span class="classname">Zend_Json_Server_Request</span> object. This object allows
                you to set necessary portions of the JSON-RPC request, including
                the request ID, parameters, and JSON-RPC specification version.
                It has the ability to load itself via <acronym class="acronym">JSON</acronym> or a set of options,
                and can render itself as <acronym class="acronym">JSON</acronym> via the
                 <span class="methodname">toJson()</span> method.
            </p>

            <p class="para">
                The request object has the following methods available:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setOptions(array $options)</span>: Specify
                        object configuration. <var class="varname">$options</var> may contain
                        keys matching any &#039;set&#039; method:
                         <span class="methodname">setParams()</span>,  <span class="methodname">setMethod()</span>,
                         <span class="methodname">setId()</span>, and
                         <span class="methodname">setVersion()</span>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addParam($value, $key = null)</span>: Add
                        a parameter to use with the method call. Parameters can be
                        just the values, or can optionally include the parameter name.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addParams(array $params)</span>: Add
                        multiple parameters at once; proxies to
                         <span class="methodname">addParam()</span>
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setParams(array $params)</span>: Set all
                        parameters at once; overwrites any existing parameters.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getParam($index)</span>: Retrieve a
                        parameter by position or name.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getParams()</span>: Retrieve all parameters at once.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setMethod($name)</span>: Set the method to call.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getMethod()</span>: Retrieve the method
                        that will be called.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">isMethodError()</span>: Determine whether
                        or not the request is malformed and would result in an error.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setId($name)</span>: Set the request
                        identifier (used by the client to match requests to responses).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getId()</span>: Retrieve the request identifier.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setVersion($version)</span>: Set the
                        JSON-RPC specification version the request conforms to.
                        May be either &#039;1.0&#039; or &#039;2.0&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getVersion()</span>: Retrieve the JSON-RPC
                        specification version used by the request.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">loadJson($json)</span>: Load the request
                        object from a <acronym class="acronym">JSON</acronym> string.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toJson()</span>: Render the request as
                        a <acronym class="acronym">JSON</acronym> string.
                    </p>
                </li>
            </ul>

            <p class="para">
                An <acronym class="acronym">HTTP</acronym> specific version is available via
                <span class="classname">Zend_Json_Server_Request_Http</span>. This class will
                retrieve the request via <var class="filename">php://input</var>, and allows access to the
                raw <acronym class="acronym">JSON</acronym> via the  <span class="methodname">getRawJson()</span> method.
            </p>
        </div>

        <div class="section" id="zend.json.server.details.zendjsonserverresponse"><div class="info"><h1 class="title">Zend_Json_Server_Response</h1></div>
            

            <p class="para">
                The JSON-RPC response payload is encapsulated in the
                <span class="classname">Zend_Json_Server_Response</span> object. This object allows
                you to set the return value of the request, whether or not the
                response is an error, the request identifier, the JSON-RPC
                specification version the response conforms to, and optionally
                the service map.
            </p>

            <p class="para">
                The response object has the following methods available:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setResult($value)</span>: Set the response result.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getResult()</span>: Retrieve the response result.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setError(Zend_Json_Server_Error $error)</span>: Set an
                        error object. If set, this will be used as the response when serializing to
                        <acronym class="acronym">JSON</acronym>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getError()</span>: Retrieve the error object, if any.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">isError()</span>: Whether or not the response is an error
                        response.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setId($name)</span>: Set the request identifier (so the
                        client may match the response with the original request).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getId()</span>: Retrieve the request identifier.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setVersion($version)</span>: Set the
                        JSON-RPC version the response conforms to.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getVersion()</span>: Retrieve the JSON-RPC
                        version the response conforms to.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toJson()</span>: Serialize the response to
                        <acronym class="acronym">JSON</acronym>. If the response is an error response, serializes
                        the error object.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setServiceMap($serviceMap)</span>: Set the
                        service map object for the response.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getServiceMap()</span>: Retrieve the
                        service map object, if any.
                    </p>
                </li>
            </ul>

            <p class="para">
                An <acronym class="acronym">HTTP</acronym> specific version is available via
                <span class="classname">Zend_Json_Server_Response_Http</span>. This class will
                send the appropriate <acronym class="acronym">HTTP</acronym> headers as well as serialize the
                response as <acronym class="acronym">JSON</acronym>.
            </p>
        </div>

        <div class="section" id="zend.json.server.details.zendjsonservererror"><div class="info"><h1 class="title">Zend_Json_Server_Error</h1></div>
            

            <p class="para">
                JSON-RPC has a special format for reporting error conditions.
                All errors need to provide, minimally, an error message and error
                code; optionally, they can provide additional data, such as a
                backtrace.
            </p>

            <p class="para">
                Error codes are derived from those recommended by <a href="http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php" class="link external">&raquo; the
                    XML-RPC EPI project</a>. <span class="classname">Zend_Json_Server</span>
                appropriately assigns the code based on the error condition. For
                application exceptions, the code &#039;-32000&#039; is used.
            </p>

            <p class="para">
                <span class="classname">Zend_Json_Server_Error</span> exposes the following
                methods:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setCode($code)</span>: Set the error code;
                        if the code is not in the accepted XML-RPC error code range,
                        -32000 will be assigned.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getCode()</span>: Retrieve the current error code.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setMessage($message)</span>: Set the error message.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getMessage()</span>: Retrieve the current error message.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setData($data)</span>: Set auxiliary data
                        further qualifying the error, such as a backtrace.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getData()</span>: Retrieve any current auxiliary error
                        data.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toArray()</span>: Cast the error to an
                        array. The array will contain the keys &#039;code&#039;, &#039;message&#039;, and &#039;data&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toJson()</span>: Cast the error to a
                        JSON-RPC error representation.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.json.server.details.zendjsonserversmd"><div class="info"><h1 class="title">Zend_Json_Server_Smd</h1></div>
            

            <p class="para">
                SMD stands for Service Mapping Description, a <acronym class="acronym">JSON</acronym> schema that
                defines how a client can interact with a particular web service.
                At the time of this writing, the <a href="http://groups.google.com/group/json-schema/web/service-mapping-description-proposal" class="link external">&raquo; specification</a>
                has not yet been formally ratified, but it is in use already
                within Dojo toolkit as well as other JSON-RPC consumer clients.
            </p>

            <p class="para">
                At its most basic, a Service Mapping Description indicates the
                method of transport (POST, <b><tt>GET</tt></b>, <acronym class="acronym">TCP</acronym>/IP,
                etc), the request envelope type (usually based on the protocol of the server), the
                target <acronym class="acronym">URL</acronym> of the service provider, and a map of services
                available. In the case of JSON-RPC, the service map is a list of
                available methods, which each method documenting the available
                parameters and their types, as well as the expected return value
                type.
            </p>

            <p class="para">
                <span class="classname">Zend_Json_Server_Smd</span> provides an object oriented
                way to build service maps. At its most basic, you pass it
                metadata describing the service using mutators, and specify
                services (methods and functions).
            </p>

            <p class="para">
                The service descriptions themselves are typically instances of
                <span class="classname">Zend_Json_Server_Smd_Service</span>; you can also pass all
                information as an array to the various service mutators in
                <span class="classname">Zend_Json_Server_Smd</span>, and it will instantiate a
                service object for you. The service objects contain information
                such as the name of the service (typically the function or
                method name), the parameters (names, types, and position), and
                the return value type. Optionally, each service can have its own
                target and envelope, though this functionality is rarely used.
            </p>

            <p class="para">
                <span class="classname">Zend_Json_Server</span> actually does all of this behind
                the scenes for you, by using reflection on the attached classes
                and functions; you should create your own service maps only if
                you need to provide custom functionality that class and function
                introspection cannot offer.
            </p>

            <p class="para">
                Methods available in <span class="classname">Zend_Json_Server_Smd</span> include:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setOptions(array $options)</span>: Setup
                        an SMD object from an array of options. All mutators
                        (methods beginning with &#039;set&#039;) can be used as keys.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setTransport($transport)</span>: Set the
                        transport used to access the service; only POST is currently supported.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getTransport()</span>: Get the current service transport.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setEnvelope($envelopeType)</span>: Set the
                        request envelope that should be used to access the
                        service. Currently, supports the constants
                        <b><tt>Zend_Json_Server_Smd::ENV_JSONRPC_1</tt></b> and
                        <b><tt>Zend_Json_Server_Smd::ENV_JSONRPC_2</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getEnvelope()</span>: Get the current request envelope.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setContentType($type)</span>: Set the
                        content type requests should use (by default, this is &#039;application/json&#039;).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getContentType()</span>: Get the current
                        content type for requests to the service.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setTarget($target)</span>: Set the <acronym class="acronym">URL</acronym>
                        endpoint for the service.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getTarget()</span>: Get the <acronym class="acronym">URL</acronym>
                        endpoint for the service.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setId($id)</span>: Typically, this is the
                        <acronym class="acronym">URL</acronym> endpoint of the service (same as the target).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getId()</span>: Retrieve the service ID
                        (typically the <acronym class="acronym">URL</acronym> endpoint of the service).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setDescription($description)</span>: Set a
                        service description (typically narrative information
                        describing the purpose of the service).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getDescription()</span>: Get the service description.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setDojoCompatible($flag)</span>: Set a flag indicating
                        whether or not the SMD is compatible with Dojo toolkit. When
                        <b><tt>TRUE</tt></b>, the generated <acronym class="acronym">JSON</acronym> SMD will
                        be formatted to comply with the format that Dojo&#039;s JSON-RPC client expects.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">isDojoCompatible()</span>: Returns the value of the
                        Dojo compatibility flag (<b><tt>FALSE</tt></b>, by default).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addService($service)</span>: Add a service
                        to the map. May be an array of information to pass to
                        the constructor of
                        <span class="classname">Zend_Json_Server_Smd_Service</span>, or an
                        instance of that class.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addServices(array $services)</span>: Add
                        multiple services at once.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setServices(array $services)</span>: Add
                        multiple services at once, overwriting any previously set services.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getService($name)</span>: Get a service by its name.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getServices()</span>: Get all attached services.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">removeService($name)</span>: Remove a
                        service from the map.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toArray()</span>: Cast the service map to an array.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toDojoArray()</span>: Cast the service map
                        to an array compatible with Dojo Toolkit.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toJson()</span>: Cast the service map to a
                        <acronym class="acronym">JSON</acronym> representation.
                    </p>
                </li>
            </ul>

            <p class="para">
                <span class="classname">Zend_Json_Server_Smd_Service</span> has the following
                methods:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setOptions(array $options)</span>: Set
                        object state from an array. Any mutator (methods
                        beginning with &#039;set&#039;) may be used as a key and set via this method.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setName($name)</span>: Set the service
                        name (typically, the function or method name).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getName()</span>: Retrieve the service name.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setTransport($transport)</span>: Set the
                        service transport (currently, only transports supported
                        by <span class="classname">Zend_Json_Server_Smd</span> are allowed).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getTransport()</span>: Retrieve the current transport.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setTarget($target)</span>: Set the <acronym class="acronym">URL</acronym>
                        endpoint of the service (typically, this will be the
                        same as the overall SMD to which the service is attached).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getTarget()</span>: Get the <acronym class="acronym">URL</acronym>
                        endpoint of the service.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setEnvelope($envelopeType)</span>: Set the
                        service envelope (currently, only envelopes supported
                        by <span class="classname">Zend_Json_Server_Smd</span> are allowed).
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getEnvelope()</span>: Retrieve the service envelope type.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addParam($type, array $options = array(), $order =
                            null)</span>: Add a parameter to the service. By default, only the
                        parameter type is necessary. However, you may also specify the order, as
                        well as options such as:
                    </p>

                    <ul class="itemizedlist">
                        <li class="listitem">
                            <p class="para">
                                <em class="emphasis">name</em>: the parameter name
                            </p>
                        </li>

                        <li class="listitem">
                            <p class="para">
                                <em class="emphasis">optional</em>: whether or not the parameter is
                                optional
                            </p>
                        </li>

                        <li class="listitem">
                            <p class="para">
                                <em class="emphasis">default</em>: a default value for the parameter
                            </p>
                        </li>

                        <li class="listitem">
                            <p class="para">
                                <em class="emphasis">description</em>: text describing the parameter
                            </p>
                        </li>
                    </ul>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">addParams(array $params)</span>: Add
                        several parameters at once; each param should be an assoc
                        array containing minimally the key &#039;type&#039; describing the
                        parameter type, and optionally the key &#039;order&#039;; any other
                        keys will be passed as <var class="varname">$options</var> to
                         <span class="methodname">addOption()</span>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setParams(array $params)</span>: Set many
                        parameters at once, overwriting any existing parameters.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getParams()</span>: Retrieve all currently set parameters.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">setReturn($type)</span>: Set the return
                        value type of the service.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">getReturn()</span>: Get the return value type of the
                        service.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toArray()</span>: Cast the service to an array.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                         <span class="methodname">toJson()</span>: Cast the service to a
                        <acronym class="acronym">JSON</acronym> representation.
                    </p>
                </li>
            </ul>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.json.xml2json.html">XML to JSON conversion</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.json.html">Zend_Json</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.layout.html">Zend_Layout</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.json.html">Zend_Json</a></li>
  <li><a href="zend.json.introduction.html">Introduction</a></li>
  <li><a href="zend.json.basics.html">Basic Usage</a></li>
  <li><a href="zend.json.advanced.html">Advanced Usage of Zend_Json</a></li>
  <li><a href="zend.json.xml2json.html">XML to JSON conversion</a></li>
  <li class="active"><a href="zend.json.server.html">Zend_Json_Server - JSON-RPC server</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>